package com.example.myapplication.tack_17;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myapplication.R;
import com.example.myapplication.tack_17.adappter.Route02Adapter;
import com.example.myapplication.tack_17.data.RotueData02;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class LuXianActivity extends AppCompatActivity {
    private ImageView exit;
    private TextView xia;
    private TextView shang;
    private RecyclerView list;
    List<RotueData02.RowsDTO> listRotue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_17_activity_lu_xian);
        init();
        Intent intent = getIntent();
        String id = intent.getStringExtra(Common.COMMON);
        getRoutev(id);
        shang_();
        exit_();
    }

    private void shang_() {
        shang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LuXianActivity.this.finish();
            }
        });
    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LuXianActivity.this.finish();
            }
        });
    }

    private void getRoutev(String id) {
        String url = "prod-api/api/bus/stop/list?linesId="+id+"&pageNum=1&pageSize=8";
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, RotueData02.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                RotueData02 rotueData02 = (RotueData02)obj;
                if(rotueData02.getCode() == 200){
                    listRotue = rotueData02.getRows();
                      runOnUiThread(new Runnable() {
                          @Override
                          public void run() {
                              RouteAdater();
                          }
                      });
                }
            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }

    private void RouteAdater() {
        Route02Adapter route02Adapter = new Route02Adapter(listRotue, LuXianActivity.this);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(LuXianActivity.this);
        list.setAdapter(route02Adapter);
        list.setLayoutManager(linearLayoutManager);
    }

    private void init() {
        exit = findViewById(R.id.exit);
        list = findViewById(R.id.list);
        xia = findViewById(R.id.xia);
        shang = findViewById(R.id.shang);
    }
}